package flyingpig.servlet;

import java.util.Timer;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

public class TaskManager implements ServletContextListener {
	/**
	 * 延迟
	 */
	public static final long DELAY = 100000;
	/**
	 * 定时器
	 */
	private Timer timer;
	/**
	 * 每小时的毫秒数
	 */
	public static final long PERIOD_HOUR = 4 * 60 * 60 * 1000;
	
	@Override
	public void contextInitialized(ServletContextEvent arg0) {
		// 定义定时器
		timer = new Timer("死页检查器 ", true);
		// 启动死页检查，每4个小时执行 一次
		timer.schedule(new JobChecker(), DELAY, PERIOD_HOUR);
	}

	@Override
	public void contextDestroyed(ServletContextEvent arg0) {

		timer.cancel(); // 定时器销毁
	}
}
